clear all
set mem 400m
set more off
use us2000, clear

***** define variables *****

replace incwage=. if incwage==0 | incwage==999999 
gen ln_incwage=ln(incwage)

gen hrwage=incwage/(wkswork1*uhrswork)
count if hrwage!=0 & hrwage!=.
count if hrwage>=1 & hrwage<=100
replace hrwage=. if !(hrwage>=1 & hrwage<=100)
gen ln_hrwage=ln(hrwage)


gen int educ_cat=educd
gen age_cat=age
recode educ_cat (1=.) (2 10=0) (21=1) (24 30=2) (40 50 61 62=3) (65 71 81 101/116=4)
recode age_cat (21/25=0) (26/35=1) (36/45=2) (46/55=3) (56/65=4)

gen int yrsinus=2000-yrimmig
gen ageimmig=age-yrsinus
gen byte recent=(yrsinus<=10)
gen byte male=(sex==1)
gen byte female=(sex==2)
gen byte married=(marst==1 | marst==2) if marst!=.
gen byte urban=(metro==2 | metro==3 | metro==4) if metro!=.


***** restrict data *****

keep if age>=21 & age<=65
keep if ageimmig>=21
keep if male
keep if recent==1
*keep if uhrswork>=10 & uhrswork<=80


******************************
***** Mincer regressions *****
******************************

***** age*education*married *****

xi: reg ln_incwage i.educ_cat*i.age_cat i.married*i.educ_cat i.married*i.age_cat 
predict ln_incwage_us_hat

xi: reg ln_hrwage i.educ_cat*i.age_cat i.married*i.educ_cat i.married*i.age_cat
predict ln_hrwage_us_hat


***** age *****

xi: reg ln_incwage i.age_cat
predict ln_incwage_us_age_hat

xi: reg ln_hrwage i.age_cat
predict ln_hrwage_us_age_hat

***** education  *****

xi: reg ln_incwage i.educ_cat
predict ln_incwage_us_educ_hat

xi: reg ln_hrwage i.educ_cat
predict ln_hrwage_us_educ_hat

***** married *****

xi: reg ln_incwage married
predict ln_incwage_us_mar_hat

xi: reg ln_hrwage married
predict ln_hrwage_us_mar_hat



collapse ln_incwage_us* ln_hrwage_us*, by(educ_cat age_cat married)

gen ln_incwage_us_=ln_incwage_us_hat if educ_cat==0 & age_cat==0 & married==0
gen ln_hrwage_us_=ln_hrwage_us_hat if educ_cat==0 & age_cat==0 & married==0
egen ln_incwage_us_base=max(ln_incwage_us_)
egen ln_hrwage_us_base=max(ln_hrwage_us_)
gen return_incwage_us=ln_incwage_us_hat-ln_incwage_us_base
gen return_hrwage_us=ln_hrwage_us_hat-ln_hrwage_us_base
gen level_incwage_us=exp(ln_incwage_us_hat)
gen level_hrwage_us=exp(ln_hrwage_us_hat)
drop ln_incwage_us_base ln_hrwage_us_base ln_incwage_us_ ln_hrwage_us_


gen ln_incwage_us_educ_=ln_incwage_us_educ_hat if educ_cat==0 & age_cat==0 & married==0
gen ln_hrwage_us_educ_=ln_hrwage_us_educ_hat if educ_cat==0 & age_cat==0 & married==0
egen ln_incwage_us_educ_base=max(ln_incwage_us_educ_)
egen ln_hrwage_us_educ_base=max(ln_hrwage_us_educ_)
gen return_incwage_us_educ=ln_incwage_us_educ_hat-ln_incwage_us_educ_base
gen return_hrwage_us_educ=ln_hrwage_us_educ_hat-ln_hrwage_us_educ_base
gen level_incwage_us_educ=exp(ln_incwage_us_educ_hat)
gen level_hrwage_us_educ=exp(ln_hrwage_us_educ_hat)
drop ln_incwage_us_educ_base ln_hrwage_us_educ_base ln_incwage_us_educ_ ln_hrwage_us_educ_

gen ln_incwage_us_age_=ln_incwage_us_age_hat if educ_cat==0 & age_cat==0 & married==0
gen ln_hrwage_us_age_=ln_hrwage_us_age_hat if educ_cat==0 & age_cat==0 & married==0
egen ln_incwage_us_age_base=max(ln_incwage_us_age_)
egen ln_hrwage_us_age_base=max(ln_hrwage_us_age_)
gen return_incwage_us_age=ln_incwage_us_age_hat-ln_incwage_us_age_base
gen return_hrwage_us_age=ln_hrwage_us_age_hat-ln_hrwage_us_age_base
gen level_incwage_us_age=exp(ln_incwage_us_age_hat)
gen level_hrwage_us_age=exp(ln_hrwage_us_age_hat)
drop ln_incwage_us_age_base ln_hrwage_us_age_base ln_incwage_us_age_ ln_hrwage_us_age_

gen ln_incwage_us_mar_=ln_incwage_us_mar_hat if educ_cat==0 & age_cat==0 & married==0
gen ln_hrwage_us_mar_=ln_hrwage_us_mar_hat if educ_cat==0 & age_cat==0 & married==0
egen ln_incwage_us_mar_base=max(ln_incwage_us_mar_)
egen ln_hrwage_us_mar_base=max(ln_hrwage_us_mar_)
gen return_incwage_us_mar=ln_incwage_us_mar_hat-ln_incwage_us_mar_base
gen return_hrwage_us_mar=ln_hrwage_us_mar_hat-ln_hrwage_us_mar_base
gen level_incwage_us_mar=exp(ln_incwage_us_mar_hat)
gen level_hrwage_us_mar=exp(ln_hrwage_us_mar_hat)
drop ln_incwage_us_mar_base ln_hrwage_us_mar_base ln_incwage_us_mar_ ln_hrwage_us_mar_

drop ln_incwage* ln_hrwage*

sort educ_cat age_cat married
save us_pwages, replace

use us_pwages, clear
sort educ_cat
save us_pwages_educ, replace

